package com.fdm.controller.properties;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.fdm.model.exceptions.BankPropertiesException;

public class BankControllerProperties 
{
	private Properties properties = new Properties();
	private String filename;
	
	public BankControllerProperties() throws BankPropertiesException {
		this.filename = "BankTeller.properties";
		this.ReadFile(filename);
	}
	
	public String getProperty(String key) throws BankPropertiesException
	{
		if (properties!=null)
		return properties.getProperty(key);
		throw new BankPropertiesException();
	}
	
	public String getProperty(String key, String defaultKey) throws BankPropertiesException
	{
		if (properties!=null)
		{
			String property = properties.getProperty(key);
			if (property==null) property=properties.getProperty(defaultKey);
			return property;
		}
		throw new BankPropertiesException();
	}

	private void ReadFile(String file) throws BankPropertiesException
	{
		try {
			InputStream inputStream = this.getClass().getClassLoader()  
	        	.getResourceAsStream(file); 
			if (inputStream!=null) properties.load(inputStream);
		} catch (FileNotFoundException e) {
			throw new BankPropertiesException();
		} catch (IOException e) {

		}
	}
}
